#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "cocos-ext.h"
#include "GameSprite.h"
#include <list>
#include <Box2D/Box2D.h>
#include "GLES-Render.h"
#include "Common.h"
#include "GameStep.h"
#include "GameHero.h"
using std::list;

USING_NS_CC;
USING_NS_CC_EXT;

class GameLayer : public cocos2d::CCLayer, public b2ContactListener
{
public:
	GameLayer();
	~GameLayer();

    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();  
    
    // a selector callback
    void menuCloseCallback(CCObject* pSender);
    
    // implement the "static node()" method manually
    CREATE_FUNC(GameLayer);

	void update(float delta);
	void onEnter();

	void loadEnemy(EEnemy r, const CCPoint& pos);
	void loadArmature(const char* name);

public:
	 bool ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent);
	 void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
	 void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
	 void ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent);
	 void pauseSchedulerAndActions();
	 void resumeSchedulerAndActions();

	 void onJumpDone();
	 bool isOutofScreen(const CCPoint& point);
	 void draw();
	 void onTouchEnabledUpdate(float dt);

public:
	bool initPhy();
	void BeginContact(b2Contact* contact);//, const b2Manifold* oldManifold);

	void onHeroContactGroup(GameSprite* pHero);
	void onEnemyContactGroup(GameSprite* pEnemy);
	void onHeroContactEnemy(GameSprite* pHero, GameSprite* pEnemy);
	void onEnemyContactEnemy(GameSprite* pEnemyA, GameSprite* pEnemyB);
	void onHeroContactStep(GameSprite* pHero, GameStep* pStep);

	void onPlayDone(CCArmature * p, MovementEventType eType, const char * id);
	void onHeroDead(CCArmature * p, MovementEventType eType, const char * id);

private:
	b2Body* m_groundBody;
	b2World* m_world;
	GLESDebugDraw m_debugDraw;

private:
	GameHero* m_pHero;
	list<int> m_vtEnemy;

	CCSprite* m_pBorderTop[2];
	CCSprite* m_pBorderBottom[2];
	GameStep* m_pSteps[3];
	int m_nCurrEnemyTag;
	int m_nBorderWidth;
	bool m_bCanJump;
	float m_tTime;

public:
	const static int s_nEnemyStartTag = 100000;
	const static int s_nHeroTag = s_nEnemyStartTag - 1;
};

#endif // __HELLOWORLD_SCENE_H__
